home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-pooglo.adb < prev    next >
Text File  |  1996-01-30  |  4KB  |  103 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                   S Y S T E M . P O O L _ G L O B A L                    --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.4 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Storage_Pools;    use System.Storage_Pools;
  27. with System.Storage_Elements; use System.Storage_Elements;
  28.  
  29. package body System.Pool_Global is
  30.  
  31.    --------------------------
  32.    -- Imported C Functions --
  33.    --------------------------
  34.  
  35.    --  It is assumed that these functions are self-protected against concurrent
  36.    --  access (should be true on a POSIX system with threads, and is part of
  37.    --  the interface requirement for the implementation of Tasking.Primitives)
  38.  
  39.    function malloc (Size : Storage_Count) return System.Address;
  40.    pragma Import (C, malloc, "malloc");
  41.  
  42.    procedure free (Address : System.Address);
  43.    pragma Import (C, free, "free");
  44.  
  45.  
  46.    ------------------
  47.    -- Storage_Size --
  48.    ------------------
  49.  
  50.    function Storage_Size
  51.      (Pool : Unbounded_No_Reclaim_Pool)
  52.      return  Storage_Count
  53.    is
  54.    begin
  55.       --  Intuitively, should return System.Memory_Size. But on Sun/Alsys,
  56.       --  System.Memory_Size > System.Max_Int, which means all you can do with
  57.       --  it is raise CONSTRAINT_ERROR...
  58.  
  59.       return Storage_Count'Last;
  60.    end Storage_Size;
  61.  
  62.    --------------
  63.    -- Allocate --
  64.    --------------
  65.  
  66.    procedure Allocate
  67.      (Pool         : in out Unbounded_No_Reclaim_Pool;
  68.       Address      : out System.Address;
  69.       Storage_Size : Storage_Count;
  70.       Alignment    : Storage_Count)
  71.    is
  72.       Allocated : System.Address;
  73.  
  74.    begin
  75.       Allocated := malloc (Storage_Size);
  76.  
  77.       --  The call to malloc returns an address whose alignment is compatible
  78.       --  with the worst case alignment requirement for the machine; thus the
  79.       --  Alignment argument can be safely ignored.
  80.  
  81.       if Allocated = Null_Address then
  82.          raise Storage_Error;
  83.       else
  84.          Address := Allocated;
  85.       end if;
  86.    end Allocate;
  87.  
  88.    ----------------
  89.    -- Deallocate --
  90.    ----------------
  91.  
  92.    procedure Deallocate
  93.      (Pool         : in out Unbounded_No_Reclaim_Pool;
  94.       Address      : System.Address;
  95.       Storage_Size : Storage_Count;
  96.       Alignment    : Storage_Count)
  97.    is
  98.    begin
  99.       free (Address);
  100.    end Deallocate;
  101.  
  102. end System.Pool_Global;
  103.